package project.web;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import project.mapper.TeacherMapper;
import project.pojo.Course;
import project.pojo.Teacher;
import project.service.TeacherService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.List;

@WebServlet("/teacherServlet")
public class TeacherServlet extends HttpServlet {
    private TeacherService service = new TeacherService();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String id = request.getParameter("teacherId");
//        System.out.println(id);
        List<Course> courses = service.showCourseByTeacherId(Long.parseLong(id));

        String data = JSON.toJSONString(courses);

        System.out.println(data);
        response.setContentType("text/json;charset=utf-8");
        response.getWriter().write(data);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
